/**********************************************************************/
/*
   Author: Karan Makkar
   Created: Oct  2023
   Updated: Aug 2025, by Youssef Assarssah
   Description: Program to compare Prakerja vs other social program applier/
                recipient counts in admin data vs national surveys.
   Outputs: Tables 1, A7, A14
*/
/**********************************************************************/

/*----------------------------------------------------*/
* Section: Setup
/*----------------------------------------------------*/

* include filepaths 
  if "$master_run" !="1" include "./Do/SET_FILEPATHS.do"

  clear
  set more off
  set matsize 11000

* Log
  cap log close
  global prefix: display %tdCYND td(`c(current_date)')
  log using "$KP_logs/${prefix}_program_receipt_counts.txt", text replace

* Switch for PMO cleaning
  local pmo_clean = 1
  local quota_clean = 1

* Set filepaths for dataset
  global sep20 "$KP_deid_susenas/Clean/sus_sep20_deid_clean.dta"
  global mar21 "$KP_deid_susenas/Clean/sus_mar21_deid_clean.dta"
  global sep21 "$KP_deid_susenas/Clean/sus_sep21_deid_clean.dta"
  global mar22 "$KP_deid_susenas/Clean/sus_mar22_deid_clean.dta"
  global aug20 "$KP_deid_sakernas/Clean/sak_aug20_deid_clean.dta"
  global feb21 "$KP_deid_sakernas/Clean/sak_feb21_deid_clean.dta"
  global aug21 "$KP_deid_sakernas/Clean/sak_aug21_deid_clean.dta"
  global sak_feb22_public "$KP_deid_sakernas/Raw/SAKERNAS_22FEB_public.dbf"

/*----------------------------------------------------*/
           /* Section: Prepare Batch Quota Data */
/*----------------------------------------------------*/

if `quota_clean' ==1 {

* Import Batch Schedule
import excel "$KP_deid_admin/Raw/00 Kartu Prakerja Batch Schedule.xlsx", sheet("Batch opening schedule") firstrow clear

* Destring Batch
replace batch = subinstr(batch, "*", "", .)
destring batch, replace

* Keep Batch <=22
keep if batch <=22

destring Beneficiariesperbatch, replace

sort batch
gen running_quota = sum(Beneficiariesperbatch)
format running_quota %10.0f

* Cumulative quota counts
foreach i in 3 5 11 17 18 22 {
	gen quota_till`i' = running_quota if batch == `i'
  gegen quota_till`i' = max(quota_till`i'), replace
	format %10.0f quota_till`i'
}

* Keep 1 obs per survey-round
keep if inrange(batch, 1, 8)

gen sus_round = 4 + _n
gen sak_round = _n

* Fill quotas with last batch before survey
gen won_quota = quota_till3 if sak_round ==5
replace won_quota = quota_till5 if sus_round ==5
replace won_quota = quota_till11 if sus_round==6 | sak_round ==6
replace won_quota = quota_till17 if sak_round ==7
replace won_quota = quota_till18 if sus_round ==7
replace won_quota = quota_till22 if sak_round ==8 | sus_round ==8 

keep won_quota sus_round sak_round 

sa "$KP_deid_admin/Clean/winquota_by_sussak_round", replace
}

/*----------------------------------------------------*/
           /* Section: Save PIP Counts */
/*----------------------------------------------------*/

u "$KP_deid_misc/Raw/province_level_transformed", clear

collapse (sum) given_Siswa, by(year)
sort year

global pip_21 = given_Siswa[1]
global pip_22 = given_Siswa[2]

/*----------------------------------------------------*/
           /* Section: Save BLT-DD Counts */
/*----------------------------------------------------*/

* Admin Data
global sep20_blt = 8040000 // https://www.cnnindonesia.com/ekonomi/20201216165024-532-583034/blt-dana-desa-baru-cair-rp2041-t-per-14-desember-2020
global sep21_blt = 8040000 // 5620000 from here: https://money.kompas.com/read/2022/01/20/203500726/kemenkeu-sebut-realisasi-penyaluran-blt-dana-desa-2021-hanya-70-29-persen. But we use Max(t,t-1)
global mar22_blt = 7500000 // https://en.antaranews.com/news/255285/pen-realization-at-503-as-of-sep-minister-hartarto

/*----------------------------------------------------*/
           /* Section: Prepare KP Admin Data */
/*----------------------------------------------------*/

if `pmo_clean' ==1 {

  * Save incentive date 
  u "$KP_deid_admin/Clean/pmo_b1-22_clean_long_deid.dta", clear
  bysort anon_id4: gegen date_incentive = max(date_incentive), replace
  collapse date_incentive, by(anon_id4)

  tempfile dateincentive
  sa `dateincentive', replace

/*********************************
calculate # of KP applicants/winners for each time period in PMO data
**********************************/
  u "$KP_deid_admin/Clean/pmo_b1-22_clean_wide_deid.dta", clear

  drop date_incentive

  * Merge in date incentive
  merge 1:1 anon_id4 using `dateincentive',
  drop if _merge ==1
  drop _merge

* Aug 2020 applicants
  egen applied_aug20 = rowtotal(applied1 applied2 applied3)
  tab applied_aug20
  replace applied_aug20 = 1 if applied_aug20 > 1
  tab applied_aug20
  la def yes_no 0 "No" 1 "Yes"
  la val applied_aug20 yes_no
  la var applied_aug20 "Applied for KP by Aug '20 (Admin Data)"


* Sep 2020 applicants
  egen applied_sep20 = rowtotal(applied1 applied2 applied3 applied4 applied5)
  tab applied_sep20
  replace applied_sep20 = 1 if applied_sep20 > 1
  tab applied_sep20
  la val applied_sep20 yes_no
  la var applied_sep20 "Applied for KP by Sept '20 (Admin Data)"

* Feb 2021 applicants
  egen applied_feb21 = rowtotal(applied1 applied2 applied3 applied4 applied5 applied6 applied7 applied8 applied9 applied10 applied11)
  tab applied_feb21
  replace applied_feb21 = 1 if applied_feb21 > 1
  tab applied_feb21
  la val applied_feb21 yes_no
  la var applied_feb21 "Applied for KP by Feb '21 (Admin Data)"

* March 2021 applicants
  egen applied_mar21 = rowtotal(applied1 applied2 applied3 applied4 applied5 applied6 applied7 applied8 applied9 applied10 applied11)
  tab applied_mar21
  replace applied_mar21 = 1 if applied_mar21 > 1
  tab applied_mar21
  la val applied_mar21 yes_no
  la var applied_mar21 "Applied for KP by Mar '21 (Admin Data)"

* Aug 2021 applicants
  egen applied_aug21 = rowtotal(applied1 applied2 applied3 applied4 applied5 applied6 applied7 applied8 applied9 applied10 applied11 applied12 applied13 applied14 applied15 applied16 applied17)
  tab applied_aug21
  replace applied_aug21 = 1 if applied_aug21 > 1
  tab applied_aug21
  la val applied_aug21 yes_no
  la var applied_aug21 "Applied for KP by Aug '21 (Admin Data)"

* Feb 2022 applicants
  egen applied_feb22 = rowtotal(applied1 applied2 applied3 applied4 applied5 applied6 applied7 applied8 applied9 applied10 applied11 applied12 applied13 applied14 applied15 applied16 applied17 applied18 applied19 applied20 applied21 applied22)
  tab applied_feb22
  replace applied_feb22 = 1 if applied_feb22 > 1
  tab applied_feb22
  la val applied_feb22 yes_no
  la var applied_feb22 "Applied for KP by Feb '22 (Admin Data)"

* Aug 2020 winners
  egen win_aug20 = rowtotal(win_in_batch1 win_in_batch2 win_in_batch3)
  tab win_aug20
  la val win_aug20 yes_no
  la var win_aug20 "Won KP by Aug '20 (Admin Data)"

* Sep 2020 winners
  egen win_sep20 = rowtotal(win_in_batch1 win_in_batch2 win_in_batch3 win_in_batch4 win_in_batch5)
  tab win_sep20
  la val win_sep20 yes_no
  la var win_sep20 "Won KP by Sept '20 (Admin Data)"

* Feb 2021 winners
  egen win_feb21 = rowtotal(win_in_batch1 win_in_batch2 win_in_batch3 win_in_batch4 win_in_batch5 ///
  win_in_batch6 win_in_batch7 win_in_batch8 win_in_batch9 win_in_batch10 win_in_batch11)
  tab win_feb21
  la val win_feb21 yes_no
  la var win_feb21 "Won KP by Mar '21 (Admin Data)"

* Mar 2021 winners
  egen win_mar21 = rowtotal(win_in_batch1 win_in_batch2 win_in_batch3 win_in_batch4 win_in_batch5 ///
  win_in_batch6 win_in_batch7 win_in_batch8 win_in_batch9 win_in_batch10 win_in_batch11)
  tab win_mar21
  la val win_mar21 yes_no
  la var win_mar21 "Won KP by Mar '21 (Admin Data)"

* Aug 2021 winners
  egen win_aug21 = rowtotal(win_in_batch1 win_in_batch2 win_in_batch3 win_in_batch4 win_in_batch5 ///
  win_in_batch6 win_in_batch7 win_in_batch8 win_in_batch9 win_in_batch10 win_in_batch11 ///
  win_in_batch12 win_in_batch13 win_in_batch14 win_in_batch15 ///
  win_in_batch16 win_in_batch17)
  tab win_aug21
  la val win_aug21 yes_no
  la var win_aug21 "Won KP by Aug '21 (Admin Data)"

* Sep 2021 winners
  egen win_sep21 = rowtotal(win_in_batch1 win_in_batch2 win_in_batch3 win_in_batch4 win_in_batch5 ///
  win_in_batch6 win_in_batch7 win_in_batch8 win_in_batch9 win_in_batch10 win_in_batch11 ///
  win_in_batch12 win_in_batch13 win_in_batch14 win_in_batch15 ///
  win_in_batch16 win_in_batch17 win_in_batch18)
  tab win_sep21
  la val win_sep21 yes_no
  la var win_sep21 "Won KP by Sep '21 (Admin Data)"

* Mar 2022 winners
  egen win_mar22 = rowtotal(win_in_batch1 win_in_batch2 win_in_batch3 win_in_batch4 win_in_batch5 ///
  win_in_batch6 win_in_batch7 win_in_batch8 win_in_batch9 win_in_batch10 win_in_batch11 ///
  win_in_batch12 win_in_batch13 win_in_batch14 win_in_batch15 ///
  win_in_batch16 win_in_batch17 ///
  win_in_batch18 win_in_batch19 win_in_batch20 win_in_batch21 win_in_batch22)
  tab win_mar22
  la val win_mar22 yes_no
  la var win_mar22 "Won KP by Mar '22 (Admin Data)"

* Feb 2022 winners
  gen win_feb22 = win_mar22
  la val win_feb22 yes_no
  la var win_feb22 "Won KP by Feb '22 (Admin Data)"

* Got cash restriction
  gen nmi_date_incentive = !mi(date_incentive)

  foreach var of varlist win_*{
    gen `var'_gc = `var' * nmi_date_incentive
  }

preserve 
* Collapse 
  collapse (sum) applied_aug20 win_aug20* applied_sep20 win_sep20* applied_feb21 win_feb21* applied_feb22 win_feb22* applied_mar21 win_mar21* applied_aug21 win_aug21* win_sep21* win_mar22*

  * Expand dataset to 1 obs per SUS/SAK round
  expand 8
  gen sus_round = 4 + _n
  gen sak_round = _n

  gen applied_pmo = applied_aug20 if sak_round ==5
  replace applied_pmo = applied_feb21 if sak_round ==6
  replace applied_pmo = applied_aug21 if sak_round ==7
  replace applied_pmo = applied_feb22 if sak_round ==8

  foreach x in "" "_gc" {
    gen won_pmo`x' = win_sep20`x' if sus_round ==5
    replace won_pmo`x' = win_mar21`x' if sus_round ==6
    replace won_pmo`x' = win_sep21`x' if sus_round ==7
    replace won_pmo`x' = win_mar22`x' if sus_round ==8
    replace won_pmo`x' = win_aug20`x' if sak_round == 5 
    replace won_pmo`x' = win_feb21`x' if sak_round ==6
    replace won_pmo`x' = win_aug21`x' if sak_round ==7
    replace won_pmo`x' = win_feb22`x' if sak_round ==8
  }
  keep applied_pmo won_pmo won_pmo_gc sus_round sak_round

  sa "$KP_deid_admin/Clean/pmo_applywin_counts_bysussak_ind", replace

restore 

* HOUSEHOLD DATA
** collapse to HH level
  drop if missing(anon_hh_id)
  di _N
  collapse (max) applied_* win_*, by(anon_hh_id)
  di _N

  collapse (sum) win_sep20* win_mar21* win_sep21* win_mar22*

  * Expand dataset to 1 obs per SUS round
  expand 4
  gen sus_round = 4 + _n

  foreach x in "" "_gc" {
    gen won_pmo`x'_hh = win_sep20`x' if sus_round ==5
    replace won_pmo`x'_hh = win_mar21`x' if sus_round ==6
    replace won_pmo`x'_hh = win_sep21`x' if sus_round ==7
    replace won_pmo`x'_hh = win_mar22`x' if sus_round ==8
  }
  keep won_pmo_hh won_pmo_gc_hh sus_round 

  sa "$KP_deid_admin/Clean/pmo_win_counts_bysus_hh", replace
}

/*----------------------------------------------------*/
           /* SUSENAS */
/*----------------------------------------------------*/

  * Load data and append
  
  * Sep 20
  use ever_BPNT aug20_BPNT jul20_BPNT jun20_BPNT may20_BPNT receive_BLTDD aug20_BLTDD jul20_BLTDD jun20_BLTDD may20_BLTDD receive_pkh_year receive_pkh_now RENUM m401 weight weind_pnl get_pk using "$sep20", clear
  gen sus_round = 5
  rename RENUM hh_id
  rename m401 person_num
  rename weind_pnl weind
  rename get_pk pk_win_comb

  * Mar 21
  append using "${mar21}", keep(ever_BPNT feb21_BPNT jan21_BPNT dec20_BPNT nov20_BPNT receive_pkh_year receive_pkh_now receive_PIP RENUM r401 weight weind hh_pk_win)
  replace sus_round = 6 if mi(sus_round)
  replace pk_win_comb = hh_pk_win if sus_round ==6
  replace hh_id = RENUM if mi(hh_id)
  replace person_num = r401 if mi(person_num)
  
  *Sep 21
  append using "${sep21}", keep(ever_BPNT aug21_BPNT jul21_BPNT jun21_BPNT may21_BPNT receive_BLTDD receive_pkh_year receive_pkh_now receive_PIP urut m401 weight hh_pk_win)
  replace sus_round = 7 if mi(sus_round)
  replace pk_win_comb = hh_pk_win if sus_round ==7
  replace hh_id =urut if mi(hh_id)
  replace person_num = m401 if mi(person_num)
  
  * Mar 22
  append using "${mar22}", keep(ever_BPNT feb22_BPNT jan22_BPNT dec21_BPNT nov21_BPNT receive_BLTDD receive_pkh_year receive_pkh_now receive_PIP URUT r401 weight WEIND get_pk)
  replace sus_round = 8 if mi(sus_round)
  replace pk_win_comb = get_pk if sus_round ==8 
  replace hh_id = URUT if mi(hh_id)
  replace person_num = r401 if mi(person_num)
  replace weind = WEIND if sus_round == 8

  * Saving individual-level PIP recipient counts
  preserve 

  gisid sus_round hh_id person_num

  replace weight = round(weight)
  collapse (sum) receive_PIP pk_win_comb [fw = weight], by(sus_round)

  tempfile ind_pip
  sa `ind_pip', replace

  restore
  
  ** Saving HH level recipient counts 
  gisid sus_round hh_id person_num
  bysort hh_id sus_round: gen hhnum = _n

  replace weight = round(weight)

  *Create hh-level KP won for Sep 20, Mar 22'
  bysort hh_id sus_round: gegen pk_win_comb = max(pk_win_comb), replace

  * Keep one obs per HH (since common response)
  keep if hhnum ==1

  *Set single BPNT var
  gen receive_BPNT = aug20_BPNT if sus_round ==5
  replace receive_BPNT = feb21_BPNT if sus_round ==6
  replace receive_BPNT = aug21_BPNT if sus_round ==7
  replace receive_BPNT = feb22_BPNT if sus_round ==8
  replace receive_BPNT = 1 if jan22_BPNT == 1 & sus_round ==8 
  replace receive_BPNT = 1 if dec21_BPNT == 1 & sus_round ==8 // March data not available, so taking from Dec

  collapse (sum) receive_BPNT receive_BLTDD receive_pkh_now receive_pkh_year hh_pk_win_comb = pk_win_comb [fw = weight], by(sus_round)

  *Merge in PIP data
  merge 1:1 sus_round using `ind_pip', nogen keepusing(receive_PIP pk_win_comb) update replace

  /**************************Non-KP Vars******************************/

  * Enter admin-data recipients for the same programs

  * BPNT. Data from here https://www.dropbox.com/scl/fi/8lvmaowk01hpfon82262p/Realisasi-Program-Sembako-PKH-140821.xlsx?rlkey=hs2xhqsn1e4lfhru4i4eezt74&dl=0, https://www.dropbox.com/scl/fi/novqg540lspdcsg0iirwn/300622-Sembako-BLT-Migor-PKH.xlsx?rlkey=pnwxp0sskqj7spsipvq8ktjp5&dl=0 , https://www.dropbox.com/home/Kartu%20Prakerja/07_Questionnaires%20and%20Data/01_Admin%20Data/06_Misc
  * Here, we have both admin data and survey data at the monthly level. Mar 22 is an exception here- 3 months are aggregated.
  gen admin_BPNT = 16647037 if sus_round ==5 // Taken from Aug 2020 (exact month)
  replace admin_BPNT = 15149570 if sus_round == 6 // Taken from Feb 2021 (exact month)
  replace admin_BPNT = 13897886 if sus_round == 7 // Taken from Aug 2021 (exact month)
  replace admin_BPNT = 18408803 if sus_round ==  8 // Taken for Jan-March 2022
  
  * Admin Data come from here: https://sid.kemendesa.go.id/village-fund
  * SUS data is at the annual level
  gen admin_BLTDD = $sep20_blt if sus_round == 5
  replace admin_BLTDD = $sep21_blt if sus_round == 7
  replace admin_BLTDD = $mar22_blt if sus_round == 8

  * PKH. Data from https://www.dropbox.com/scl/fi/8lvmaowk01hpfon82262p/Realisasi-Program-Sembako-PKH-140821.xlsx?rlkey=hs2xhqsn1e4lfhru4i4eezt74&dl=0, https://www.dropbox.com/scl/fi/novqg540lspdcsg0iirwn/300622-Sembako-BLT-Migor-PKH.xlsx?rlkey=pnwxp0sskqj7spsipvq8ktjp5&dl=0 
  * Here, we have "Receive Now" in Susenas, and number of recipients quarterly in admin data. We should expect the SUS numbers to slightly underestimate.
  gen admin_pkh_now = 9545093 if sus_round == 5 // Phase 1 2021. This is the closest I have for now.
  replace admin_pkh_now = 9545093 if sus_round == 6 // Phase 1 2021
  replace admin_pkh_now = 9552714	 if sus_round == 7 // Phase 2 2021
  replace admin_pkh_now = 9804292 if sus_round == 8 // Phase 1 2022

* PIP. Data from $KP_deid_misc/Clean/province_level_transformed
* Here, we have annual PIP data for both admin and survey data. However, the year in question doesn't overlap perfectly (calendar year fro admin vs year before survey for survey)
  gen admin_PIP = $pip_21 if sus_round == 6 // Annual recipient counts 2021
  replace admin_PIP = $pip_21 if sus_round == 7 // Annual recipient counts 2021
  replace admin_PIP = $pip_22 if sus_round == 8 // Annual recipient counts 2022

  gen perc_BPNT = (receive_BPNT/admin_BPNT)*100
  gen perc_BLTDD = (receive_BLTDD/admin_BLTDD)*100
  gen perc_pkh_now = (receive_pkh_now/admin_pkh_now)*100
  gen perc_PIP = (receive_PIP/admin_PIP)*100

  *Label
    foreach var of varlist admin_* {
    label var `var' "\hspace{0.25cm} Admin Data"
  }

  foreach var of varlist receive_* {
    label var `var' "\hspace{0.25cm} Welfare Survey Data"
  }

  foreach var of varlist perc_* {
    label var `var' "\hspace{0.25cm} (Welfare Survey/Admin) Data (\%)"
  }

  * Summarize
  eststo t13: estpost summ receive_BPNT admin_BPNT perc_BPNT receive_pkh_now admin_pkh_now perc_pkh_now receive_BLTDD admin_BLTDD perc_BLTDD if sus_round == 5
  eststo t14: estpost summ receive_BPNT admin_BPNT perc_BPNT receive_pkh_now admin_pkh_now perc_pkh_now receive_PIP admin_PIP perc_PIP if sus_round == 6
  eststo t15: estpost summ receive_BPNT admin_BPNT perc_BPNT receive_pkh_now admin_pkh_now perc_pkh_now receive_PIP admin_PIP perc_PIP receive_BLTDD admin_BLTDD perc_BLTDD if sus_round == 7
  eststo t16: estpost summ receive_BPNT admin_BPNT perc_BPNT receive_pkh_now admin_pkh_now perc_pkh_now receive_PIP admin_PIP perc_PIP receive_BLTDD admin_BLTDD perc_BLTDD if sus_round == 8

  /************************** KP  ******************************/

  * Merge in PMO and Quota Data
  fmerge 1:1 sus_round using "$KP_deid_admin/Clean/pmo_win_counts_bysus_hh", assert(2 3) keep(3) nogen
  fmerge 1:1 sus_round using "$KP_deid_admin/Clean/winquota_by_sussak_round", assert(2 3) keep(3) nogen keepusing(won_quota)

  rename won_pmo_hh won_pmo
  rename won_pmo_gc_hh won_pmo_gc
  gen perc_pmo = (hh_pk_win_comb/won_pmo)*100
  gen perc_pmo_gc = (hh_pk_win/won_pmo_gc)*100

  * Regularizing varname
  cap drop report_selected
  rename hh_pk_win report_selected

  *Label
  label var won_pmo "\hspace{0.25cm} Win in Administrative data"
  label var report_selected "\hspace{0.25cm} Report Selected in Survey data"
  label var perc_pmo "\hspace{0.25cm} Survey Winners/Admin Winners (\%)"

  * Summarize
  foreach x in "" "_gc" {
    eststo t5`x': estpost summ won_pmo`x' report_selected perc_pmo`x' if sus_round == 5
    eststo t6`x': estpost summ won_pmo`x' report_selected perc_pmo`x' if sus_round == 6
    eststo t7`x': estpost summ won_pmo`x' report_selected perc_pmo`x' if sus_round == 7
    eststo t8`x': estpost summ won_pmo`x' report_selected perc_pmo`x' if sus_round == 8
  }

  tempfile suslabel
  sa `suslabel', replace


/*----------------------------------------------------*/
           /* SAKERNAS */
/*----------------------------------------------------*/

* Save FEB 22 Data
  import dbase using "${sak_feb22_public}", clear
  
  * Define yes/no label
  la def yes_no 0 "No" 1 "Yes"

* applied to KP
  cap gen report_applied = R43B == 1
  lab var report_applied "Reported Applying to KP (Sakernas Feb '22)"

* received KP
  cap gen report_selected = R43E == 1
  lab var report_selected "Reported Receiving KP (Sakernas Feb '22)"

  rename WEIGHT weight

  tempfile feb22
  sa `feb22', replace

  * Load data and append
  
  * Aug 20
  use report_applied report_selected weight using "${aug20}", clear
  gen sak_round = 5

  * Feb 21
  append using "${feb21}", keep(report_applied report_selected weight)
  replace sak_round = 6 if mi(sak_round)

  *Aug 21
  append using "${aug21}", keep(report_applied report_selected weight)
  replace sak_round = 7 if mi(sak_round)
  
  * Feb 22
  append using `feb22', keep(report_applied report_selected weight)
  replace sak_round = 8 if mi(sak_round)

  collapse (sum) report_selected report_applied [fw = weight], by(sak_round)
  
  * Merge in PMO and Quota Data
  fmerge 1:1 sak_round using "${KP_deid_admin}/Clean/pmo_applywin_counts_bysussak_ind", assert(2 3) keep(3) nogen 
  fmerge 1:1 sak_round using "${KP_deid_admin}/Clean/winquota_by_sussak_round", assert(2 3) keep(3) nogen keepusing(won_quota)

  gen perc_pmo = (report_selected/won_pmo)*100
  gen perc_pmo_gc = (report_selected/won_pmo_gc)*100
  gen perc_pmo_a = (report_applied/applied_pmo)*100

  *Label
  label var won_pmo "\hspace{0.25cm} Win in Administrative Data"
  label var won_pmo_gc "\hspace{0.25cm} Win and Get Payment in Administrative data"
  label var report_selected "\hspace{0.25cm} Report Selected in Survey Data"
  label var perc_pmo "\hspace{0.25cm} Survey Winners/Admin Winners (\%)"
  label var perc_pmo_gc "\hspace{0.25cm} Survey Winners/Admin Winners (\%)"
  label var applied_pmo "Apply in Administrative Data"
  label var report_applied "Report Applied in Survey Data"
  label var perc_pmo_a "Survey Applicants/Admin Applicants (\%)"

  * Summarize
  foreach x in "" "_gc" {
    eststo t1`x': estpost summ won_pmo`x' report_selected perc_pmo`x' if sak_round == 5
    eststo t2`x': estpost summ won_pmo`x' report_selected perc_pmo`x' if sak_round == 6
    eststo t3`x': estpost summ won_pmo`x' report_selected perc_pmo`x' if sak_round == 7
  }
  
  summ perc_pmo if sak_round == 8
  local feb22 = round(r(mean), 1)
  di "Feb 22 Survey/PMO Win Percentage: `feb22'%"

  * Gen dummy missing models for table
  gen zero = 0
  forvalue i = 9/12{
    eststo t`i': estpost summ zero
  }

  * Import Labels for SUS data
  append using `suslabel'

  * Make Table
  foreach x in "" "_gc" {

    if "`x'" == "" local tabname = "Table1"
    else local tabname = "TableA14"

    esttab t1`x' t2`x' t3`x' t5`x' t6`x' t7`x' t8`x' using $KP_output/tables/descriptive/tex/`tabname'.tex, ///
    cells("mean(pattern(1 1 1 1 1 1 1 ) fmt(%10.0fc))") replace label ///
    mtitle("Aug '20" "Feb '21" "Aug '21" "Sep '20" "Mar '21" "Sep '21" "Mar '22" ) collabels(none) noobs nonum ///
    mgroups("Workforce Survey Wave (Individual Level)" "Welfare Survey Wave (HH Level)", pattern(1 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
    prehead(`"\hline \hline"') ///
      posthead(`"& (1) & (2) & (3) & (4) & (5) & (6) & (7) \\"' `"\hline \\ \multicolumn{4}{l}{\textit{Panel A: Kartu Prakerja Recipient Counts}} \\\\[-2.5ex]"') ///
      fragment ///
      substitute(" 0" " ")
  
  * Make Table
  esttab t9 t10 t11 t13 t14 t15 t16 using $KP_output/tables/descriptive/tex/`tabname'.tex, ///
   cells("mean(pattern(1 1 1 1) fmt(%10.0fc))") label ///
   collabels(none) noobs ///
    booktabs ///
    nomtitles nonumbers ///
    posthead(`"\hline \\ \multicolumn{4}{l}{\textit{Panel B: Social Program Recipient Counts}} \\\\[-2.5ex]"') ///
    postfoot(`"\\ Batches & 1-3 & 1-11 & 1-17 & 1-5 & 1-11 & 1-18 & 1-22 \\"' `"\hline"') ///
    fragment ///
    append ///
    order(admin_BPNT receive_BPNT perc_BPNT admin_pkh_now receive_pkh_now perc_pkh_now admin_PIP receive_PIP perc_PIP admin_BLTDD receive_BLTDD  perc_BLTDD) ///
    refcat(admin_BPNT "\underline{BPNT Recipient Count}" admin_pkh_now "\underline{PKH Recipient Count}" admin_PIP "\underline{PIP Recipient Count (Individual)}" admin_BLTDD "\underline{BLT-DD Recipient Count}" , nolabel) ///
    substitute(".&" "&") drop(zero)
}
   * Summarize Report Apply
  eststo t1: estpost summ applied_pmo report_applied perc_pmo_a if sak_round == 5
  eststo t2: estpost summ applied_pmo report_applied perc_pmo_a if sak_round == 6
  eststo t3: estpost summ applied_pmo report_applied perc_pmo_a if sak_round == 7

  summ perc_pmo_a if sak_round == 8
  local feb22 = round(r(mean), 1)
  di "Feb 22 Survey/PMO Applied Percentage: `feb22'%"

  * Make Table
  esttab t1 t2 t3 using $KP_output/tables/descriptive/tex/TableA7.tex, ///
   cells("mean(pattern(1 1 1) fmt(%10.0fc))") replace label ///
   mtitle("Aug '20" "Feb '21" "Aug '21") collabels(none) noobs nonum ///
   mgroups("Workforce Survey Wave (Individual Level)", pattern(1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
   prehead(`"\hline \hline"') ///
   posthead(`"& (1) & (2) & (3) \\"' `"\hline \\"') ///
   prefoot(`"\\ "') ///
   postfoot(`"Batches & 1-3 & 1-11 & 1-17 \\"' `"\hline"')